package com.whfc.ms.api.emp.controller;

import com.whfc.common.result.ListData;
import com.whfc.common.result.Result;
import com.whfc.common.result.ResultUtil;
import com.whfc.common.util.SessionAttr;
import com.whfc.emp.dto.AppEmpBankDTO;
import com.whfc.emp.param.AppEmpBankAddParam;
import com.whfc.emp.param.AppEmpBankEditParam;
import com.whfc.emp.param.EnableBankParam;
import com.whfc.fuum.entity.SysUser;
import com.whfc.ms.api.emp.service.MsAppEmpBankService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author sun_guodong
 * @description 人员银行账户
 * @date 2020-08-08
 */
@RestController
@RequestMapping("/ms/api/emp/bank")
public class AppEmpBankController {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private MsAppEmpBankService appEmpBankService;

    @GetMapping("/list")
    public Result list(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                       @RequestParam("empId") Integer empId) {
        logger.info("人员银行账户列表,loginer:{},empId:{}", user.getUsername(), empId);
        ListData<AppEmpBankDTO> listData = appEmpBankService.list(empId);
        return ResultUtil.success(listData);
    }

    @PostMapping("/add")
    public Result add(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                      @Validated @RequestBody AppEmpBankAddParam param) {
        logger.info("添加银行账户,loginer:{},param:{}", user.getUsername(), param.toString());
        appEmpBankService.add(param);
        return ResultUtil.success();
    }

    @PostMapping("/edit")
    public Result edit(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                       @Validated @RequestBody AppEmpBankEditParam param) {
        logger.info("编辑银行账户,loginer:{},param:{}", user.getUsername(), param.toString());
        appEmpBankService.edit(param);
        return ResultUtil.success();
    }

    @PostMapping("/enable")
    public Result enable(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                         @Validated @RequestBody EnableBankParam param) {
        logger.info("启用禁用银行账户,loginer:{},param:{}", user.getUsername(), param.toString());
        appEmpBankService.enable(param);
        return ResultUtil.success();
    }

    @PostMapping("/del/{bankId}")
    public Result del(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                      @PathVariable("bankId") Integer bankId) {
        logger.info("删除银行账户,loginer:{},bankId:{}", user.getUsername(), bankId);
        appEmpBankService.del(bankId);
        return ResultUtil.success();
    }

}
